<?php

require_once('quail/reporters/reporter.demo.php');

class reportMoodleDemo extends reportDemo {
	
	var $images = array(
		QUAIL_TEST_SEVERE => 'severe.png',
		QUAIL_TEST_MODERATE => 'moderate.png',
		QUAIL_TEST_SUGGESTION => 'suggestion.png',
	);
	
	/**
	*	The getReport method - we iterate through every test item and
	*	add additional attributes to build the report UI.
	*	@return string A fully-formed HTML document.
	*/
	function getReport() {
		global $CFG;
		$problems = $this->guideline->getReport();
		if(is_array($problems)) {
			foreach($problems as $testname => $test) {
				if(!isset($this->options->display_level) || $this->options->display_level >= $test['severity'] && is_array($test)) {
					foreach($test as $k => $problem) {
						if(is_object($problem) && property_exists($problem, 'element') && is_object($problem->element)) {
							$existing = $problem->element->getAttribute('class');
							$problem->element->setAttribute('class', 
							$existing .' '. $this->classnames[$test['severity']]);
							$link = $this->dom->createElement('a');
							$link = $problem->element->parentNode->insertBefore($link, $problem->element);
							$link->setAttribute('href', 
								$CFG->wwwroot .'/filter/accessibility/test_info.php?test='. $testname);
							$link->setAttribute('class', 'accessibility-popup');
							$image = $this->dom->createElement('img');
							$image = $link->appendChild($image);
							$image->setAttribute('alt', $testname);
							if($problem->message) {
								$image->setAttribute('title', $problem->message);
							}
							$image->setAttribute('src', $CFG->wwwroot .
				'/filter/accessibility/images/'. $this->images[$test['severity']]);
						}
					}
				}
			}
		}		

		return $this->completeURLs($this->dom->saveHTML(), implode('/', $this->path));
	}
}